package com.lanou.controller;

import com.google.gson.Gson;
import com.lanou.service.SelectService;
import com.lanou.utils.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(name = "CategoryServlet",urlPatterns = "/category")
public class CategoryServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
    private SelectService selectService = new SelectService();
    //查找种类
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("application/json;charset=utf-8");
        AjaxResult ar = new AjaxResult();
        PrintWriter out = response.getWriter();
        List list = selectService.selectCategory();
        if (list!=null){
            ar.setCode(1000);
            ar.setMsg("搜索成功");
            ar.setData(list);
        }else {
            ar.setCode(1001);
            ar.setMsg("搜索失败");
        }
        out.write(new Gson().toJson(ar));
        out.close();
    }
}
